#ifndef _LINKTREE_H_
#define _LINKTREE_H_

#include "DoubleLinkList.h"
#define TreeElementType char*


typedef void (*ClearCallback)(void*);
typedef void (*PrintCallback)(void*);
typedef void (*FuncCallback)(void*,void*);

class TreeNode 
{
public:
    TreeElementType data; // 数据域
    TreeNode *parent; // 双亲节点
    DoubleLinkList childs; // 孩子节点列表
    ClearCallback ClearPtr;
    PrintCallback PrintPtr;
    FuncCallback funcPtr;

    // 构造函数
    TreeNode(TreeElementType element = NULL, TreeNode *parent = NULL):data(element), parent(parent) 
    {
        DoubleLinkList();
    }
    
    void ConnectBranch(TreeNode *parent,TreeNode *child);
    void DisconnectBranch(TreeNode *parent,TreeNode *child);
    void TravelTreeNode(TreeNode *node,int deepth,void(*PrintPtr)(void*));
    TreeNode *FindChildNode(TreeNode *parent,void* value,bool(*funcPtr)(void *,void *));
    void setClearPtr(ClearCallback callback) 
    {
        ClearPtr = callback;
    }
    void setPrintPtr(PrintCallback callback) 
    {
        PrintPtr = callback;
    }
    void setFuncPtr(FuncCallback callback) 
    {
        funcPtr = callback;
    }
};

// 链表树类
class LinkTree 
{
public:

    // 构造函数
    LinkTree():root(NULL) {}

    // 析构函数
    ~LinkTree();

    TreeNode* FindLinkTreeNode(void* value,bool(*funcPtr)(void *,void *));
    DoubleLinkList FindAllLeafBranches();

private:
    TreeNode *root; // 树的根
};

#endif